package demo1;

public class LeetCode34 {
    public int[] searchRange(int[] nums, int target) {
        int n = nums.length;
        int[] arr = new int[]{-1, -1};
        if(n == 0) return arr;
        int left = 0, right = n - 1;
        //左端点
        while (left < right) {
            int mid = left + (right - left) / 2;
            if(nums[mid] >= target) right = mid;
            else left = mid + 1;
        }
        if(nums[left] != target) return arr;
        else arr[0] = left;
        //右端点
        //left = 0;
        right = n - 1;
        while (left < right) {
            int mid = left + (right - left + 1) / 2;
            if(nums[mid] > target) right = mid - 1;
            else left = mid;
        }
        arr[1] = left;
        return arr;
    }
}
